package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.pojo.NotificationReadStatus;
import com.example.pojo.dto.NotificationDTO;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NotificationReadStatusMapper extends MPJBaseMapper<NotificationReadStatus>, BaseMapper<NotificationReadStatus> {
    // 批量插入方法
    int insertBatchSomeColumn(List<NotificationReadStatus> entities);

    @Select("SELECT\n" +
            "            n.notification_id,\n" +
            "            n.title,\n" +
            "            n.image,\n" +
            "            n.content,\n" +
            "            n.publish_date,\n" +
            "            n.publisher_id,\n" +
            "            n.notification_type,\n" +
            "            nrs.user_id,\n" +
            "            nrs.is_read\n" +
            "        FROM\n" +
            "            notification_read_status nrs\n" +
            "                JOIN\n" +
            "            notification n ON nrs.notification_id = n.notification_id\n" +
            "        WHERE\n" +
            "            nrs.user_id = #{userId}\n" +
            "        ORDER BY\n" +
            "            n.publish_date DESC")
    List<NotificationDTO> getNotificationByUserId(@Param("userId") Long userId);

    @Select("SELECT \n" +
            "    n.notification_id,\n" +
            "    n.title,\n" +
            "    n.image,\n" +
            "    n.content,\n" +
            "    n.publish_date,\n" +
            "    n.publisher_id,\n" +
            "    n.notification_type,\n" +
            "\t\tnrs.user_id,\n" +
            "    nrs.is_read\n" +
            "FROM \n" +
            "    notification_read_status nrs\n" +
            "JOIN \t\n" +
            "    notification n ON nrs.notification_id = n.notification_id\n" +
            "WHERE \n" +
            "    nrs.user_id = #{userId} AND n.notification_type = #{notificationType}\n" +
            "ORDER BY \n" +
            "    n.publish_date DESC")
    List<NotificationDTO> getNotificationByUserIdAndType(@Param("userId") Long userId,@Param("notificationType") Integer notificationType);

    @Select("SELECT \n" +
            "    n.notification_id,\n" +
            "    n.title,\n" +
            "    n.image,\n" +
            "    n.content,\n" +
            "    n.publish_date,\n" +
            "    n.publisher_id,\n" +
            "    n.notification_type,\n" +
            "\t\tnrs.user_id,\n" +
            "    nrs.is_read\n" +
            "FROM \n" +
            "    notification_read_status nrs\n" +
            "JOIN \t\n" +
            "    notification n ON nrs.notification_id = n.notification_id\n" +
            "WHERE \n" +
            "    n.publisher_id = #{userId}\n" +
            "ORDER BY \n" +
            "    n.publish_date DESC")
    List<NotificationDTO> getMyNotification(@Param("userId") Long userId);

    @Select("SELECT \n" +
            "    n.notification_id,\n" +
            "    n.title,\n" +
            "    n.image,\n" +
            "    n.content,\n" +
            "    n.publish_date,\n" +
            "    n.publisher_id,\n" +
            "    n.notification_type,\n" +
            "\t\tnrs.user_id,\n" +
            "    nrs.is_read\n" +
            "FROM \n" +
            "    notification_read_status nrs\n" +
            "JOIN \t\n" +
            "    notification n ON nrs.notification_id = n.notification_id\n" +
            "WHERE \n" +
            "    nrs.user_id = #{userId} AND n.notification_type = #{notificationType} AND nrs.is_read=0\n" +
            "ORDER BY \n" +
            "    n.publish_date DESC")
    List<NotificationDTO> getNotReadNotificationByUserIdAndType(@Param("userId") Long userId,@Param("notificationType") Integer notificationType);
}
